﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EMANIFEST.Dtos;

namespace TestSaveRecord
{
    /// <summary>
    /// Summary description for TestCrewRecord
    /// </summary>
    [TestClass]
    public class TestCrewRecord
    {
        public TestCrewRecord()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestCrew()
        {
            try
            {
                CrewDto cre = new CrewDto();
                Guid id = new Guid("95577A12-CB0D-490E-84F6-3EF38FD3A4D6");//Guid.NewGuid();
                cre.CrewId = id;
                cre.DocumentId = new Guid("DAB27624-2270-4C40-A977-8856C4A8388A");
                cre.FamilyName = "Nguyen";
                cre.GivenName = "Tien Tan";
                cre.Rank = "Thuyen Truong";
                cre.StateId = new Guid("a47926b6-0a36-48cc-ae88-94016c4fb169");
                cre.BirthDate = DateTime.Now;
                cre.BirthPlace = "Phuc Tho Viet Nam";
                cre.PassportType = "T002";
                cre.PassportNumber = "12345";
                cre.PassportValidDate = DateTime.Now;
                cre.CreaterId = new Guid("93ec220c-5b57-4dac-88aa-9a314e1a7424");
                cre.CreatedDate = DateTime.Now;

                eManifestService.EmanifestServiceClient client = new eManifestService.EmanifestServiceClient();
                client.SaveCrewRecord(cre);

                // check exists
                CrewDto cdto = client.GetCrewById(cre.CrewId);
                if (cdto != null)
                    Console.WriteLine("cap nhat thanh cong");
                else
                    Console.WriteLine("cap nhat that bai");
                
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }


        [TestMethod]
        public void DeleteCrew()
        {
            try
            {
                eManifestService.EmanifestServiceClient client = new eManifestService.EmanifestServiceClient();

                ResponseDto res = client.DeleteCrewById(new Guid("95577A12-CB0D-490E-84F6-3EF38FD3A4D6"));
                Console.WriteLine(res.IsSuccess);
                CrewDto cdto = client.GetCrewById(new Guid("95577A12-CB0D-490E-84F6-3EF38FD3A4D6"));
                if (cdto == null)
                    Console.WriteLine("Delete thanh cong");
                else
                    Console.WriteLine("Delete that bai");
            }
            catch
            {
                
            }
        }
    }
}
